package gwt.seca.client.agents;

import javax.vecmath.Vector3f;

public class Ernest7Anim extends AbstractAnim {

	final static int ANIM_MOVE = 1;
	final static int ANIM_BUMP = 2;
	final static int ANIM_TURN_LEFT = 3;
	final static int ANIM_TURN_RIGHT = 4;
	final static int ANIM_TOUCH_FORWARD = 5;
	final static int ANIM_TOUCH_LEFT = 6;
	final static int ANIM_TOUCH_RIGHT = 7;
	
	public Ernest7Anim(Ernest7Model model) {
		super(model);
		mModel = model;
	}
	
	protected void startImpl(Vector3f trans, Vector3f rot) {
		float dist = trans.length();
		float rotZ = rot.getZ();
		switch (mAnimID) {
		case ANIM_MOVE:
			mNumberOfCycles = 0;
			mExtremeBodyTrans.set(1, 0, 0);
			mExtremeBodyRot.set(0, 0, 0);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, 0);
			mExtremeLeftAntennaRot.set(0, 0, 0);
			mExtremeRightLegRot.set(0, 0, 20);
			mExtremeLeftLegRot.set(0, 0, -20);
			if (!mModel.mDiscrete) {
				mExtremeBodyTrans.set(dist, 0, 0);
			}
			break;
		case ANIM_BUMP:
			mNumberOfCycles = 1;
			mExtremeBodyTrans.set(0.2f, 0, 0);
			mExtremeBodyRot.set(0, 0, 0);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, -80);
			mExtremeLeftAntennaRot.set(0, 0, 80);
			mExtremeRightLegRot.set(0, 0, 20);
			mExtremeLeftLegRot.set(0, 0, -20);
			if (!mModel.mDiscrete) {
				mExtremeBodyTrans.set(0.05f, 0, 0);
			}
			break;
		case ANIM_TURN_LEFT:
			mNumberOfCycles = 0;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, 90);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, 0);
			mExtremeLeftAntennaRot.set(0, 0, 0);
			mExtremeRightLegRot.set(0, 0, 20);
			mExtremeLeftLegRot.set(0, 0, 10);
			if (!mModel.mDiscrete) {
				mExtremeBodyRot.set(0, 0, rotZ);
			}
			break;
		case ANIM_TURN_RIGHT:
			mNumberOfCycles = 0;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, -90);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, 0);
			mExtremeLeftAntennaRot.set(0, 0, 0);
			mExtremeRightLegRot.set(0, 0, -10);
			mExtremeLeftLegRot.set(0, 0, -20);
			if (!mModel.mDiscrete) {
				mExtremeBodyRot.set(0, 0, rotZ);
			}
			break;
		case ANIM_TOUCH_FORWARD:
			mNumberOfCycles = 1;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, 0);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, 30);
			mExtremeLeftAntennaRot.set(0, 0, -30);
			mExtremeRightLegRot.set(0, 0, 0);
			mExtremeLeftLegRot.set(0, 0, 0);
			break;
		case ANIM_TOUCH_LEFT:
			mNumberOfCycles = 1;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, 30);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, 30);
			mExtremeLeftAntennaRot.set(0, 0, 30);
			mExtremeRightLegRot.set(0, 0, 20);
			mExtremeLeftLegRot.set(0, 0, 10);
			break;
		case ANIM_TOUCH_RIGHT:
			mNumberOfCycles = 1;
			mExtremeBodyTrans.set(0, 0, 0);
			mExtremeBodyRot.set(0, 0, -30);
			mNumberOfCycles2 = 1;
			mExtremeRightAntennaRot.set(0, 0, -30);
			mExtremeLeftAntennaRot.set(0, 0, -30);
			mExtremeRightLegRot.set(0, 0, -10);
			mExtremeLeftLegRot.set(0, 0, -20);
			break;
		default:
			mAnimID = 0;
			mModel = null;
		}
	}
	public void updateImpl(float scale, float scale2) {
		mModel.mBodyTrans.scale(scale, mExtremeBodyTrans);
		mModel.mBodyRot.scale(scale, mExtremeBodyRot);
		mModel.mRightAntennaRot.scale(scale2, mExtremeRightAntennaRot);
		mModel.mLeftAntennaRot.scale(scale2, mExtremeLeftAntennaRot);
		mModel.mRightLegRot.scale(scale2, mExtremeRightLegRot);
		mModel.mLeftLegRot.scale(scale2, mExtremeLeftLegRot);
	}
	public void stopImpl() {
		mModel.mBodyTrans.set(0, 0, 0);
		mModel.mBodyRot.set(0, 0, 0);
		mModel.mRightAntennaRot.set(0, 0, 0);
		mModel.mLeftAntennaRot.set(0, 0, 0);
		mModel.mRightLegRot.set(0, 0, 0);
		mModel.mLeftLegRot.set(0, 0, 0);
	}
	
	protected Ernest7Model mModel;
	private Vector3f mExtremeBodyTrans = new Vector3f();
	private Vector3f mExtremeBodyRot = new Vector3f();
	private Vector3f mExtremeRightAntennaRot = new Vector3f();
	private Vector3f mExtremeLeftAntennaRot = new Vector3f();
	private Vector3f mExtremeRightLegRot = new Vector3f();
	private Vector3f mExtremeLeftLegRot = new Vector3f();
}
